package com.iye.puretennis.custom;

import android.content.Context;
import android.graphics.Bitmap;
import com.iye.puretennis.domain.UserToken;
import com.iye.puretennis.helper.DBManager;
import com.iye.puretennis.helper.ServerAccessHelper;
import com.iye.puretennis.utils.ImageUtils;
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * Created with IntelliJ IDEA.
 * User: jing wu
 * Date: 2015/1/15
 * Time: 12:24
 */
public class CustomImageDownloader extends BaseImageDownloader {

    private String token;

    public CustomImageDownloader(Context context, String token) {
        super(context);
        this.token = token;
    }

    public CustomImageDownloader(Context context, int connectTimeout, int readTimeout) {
        super(context, connectTimeout, readTimeout);
    }

    @Override
    public InputStream getStream(String imageUri, Object extra) throws IOException {

        Bitmap bitmap = ServerAccessHelper.loadUserImage(extra.toString(), token);
        if (bitmap == null) {
            return null;
        }
        return ImageUtils.bitmapToInputStream(bitmap);

    }


}
